using OracleInternal.Common;
using OracleInternal.ServiceObjects;

namespace OracleInternal.TTC
{
	internal class NotificationMessagePayload
	{
		private OracleConnectionImpl m_orclConnImpl;

		internal NotificationMessagePayload(OracleConnectionImpl orclConnImpl)
		{
			m_orclConnImpl = orclConnImpl;
		}

		internal void Receive(long regIdFromServer)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.NotificationMessagePayload, OracleTraceFuncName.Receive, "Receiving payload for SvrRegId=" + regIdFromServer);
			}
			try
			{
				int num = (int)m_orclConnImpl.m_marshallingEngine.UnmarshalUB4();
				int num2 = (int)m_orclConnImpl.m_marshallingEngine.UnmarshalUB4();
				int num3 = (int)m_orclConnImpl.m_marshallingEngine.UnmarshalUB4();
				int num4 = (int)m_orclConnImpl.m_marshallingEngine.UnmarshalUB4();
				byte[] array = null;
				if (num4 > 0)
				{
					array = new byte[num4];
					int[] array2 = new int[1];
					m_orclConnImpl.m_marshallingEngine.UnmarshalCLR(array, 0, array2, array.Length);
					num4 = array2[0];
				}
				else if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.TTC, OracleTraceClassName.NotificationMessagePayload, OracleTraceFuncName.Receive, "Empty Payload Received -> Timeout Notification");
				}
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					string text = $"Enqueue Notification [regIdFromServer:{regIdFromServer}, chunkNumber:{num3}, payloadType:{num}, payloadFlag:{num2}, rawPayload lemgth:{((array != null) ? array.Length : 0)}";
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.TTC, OracleTraceClassName.NotificationMessagePayload, OracleTraceFuncName.Receive, text);
				}
				NotificationContext.EnqueueNotification(m_orclConnImpl, regIdFromServer, m_orclConnImpl.m_marshallingEngine.m_dbCharSetConv, num, num2, array, bLastNotification: false);
				m_orclConnImpl.m_marshallingEngine.UnmarshalUB4();
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.NotificationMessagePayload, OracleTraceFuncName.Receive);
				}
			}
		}
	}
}
